negotiator.issue
Class Objective

java.lang.Object
  extended by negotiator.issue.Objective
All Implemented Interfaces:
java.io.Serializable, javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode
Direct Known Subclasses:
Issue

public class Objective
extends java.lang.Object
implements javax.swing.tree.MutableTreeNode, java.io.Serializable

Some work needs to be done to guarantee consistency of the tree. Methods like setParent don't signal the parent that it has a new child yet. Also check the constructors for this... The whole code needs a review anyway, though with current use it works fine :-)

Author:
Richard Noorlandt, W. Pasman
See Also:
Serialized Form

Constructor Summary
Objective()
           
Objective(Objective parent)
           
Objective(Objective parent, java.lang.String name)
           
Objective(Objective parent, java.lang.String name, int nr)
           
 
Method Summary
 void addChild(Objective newObjective)
          Adds a child to this Objective.
 java.util.Enumeration<Objective> children()
           
 boolean equalContents(Objective obj)
          check the contents but don't check for the class type anymore.
 boolean equals(java.lang.Object o)
           
 boolean getAllowsChildren()
           
 Objective getChildAt(int childIndex)
           
 int getChildCount()
           
 java.util.ArrayList<Objective> getChildren()
          Wouter: added bcause I dont have time to change all Vector and Enumerators to ArrayList code
 Objective getChildWithID(int ID)
           
 java.lang.String getDescription()
           
 int getHighestObjectiveNr(int lowerBound)
          This method recursively calculates the highest Objective / Issue number in the subtree rooted at the callee.
 int getIndex(javax.swing.tree.TreeNode node)
           
 java.lang.String getName()
           
 int getNumber()
           
 Objective getObjective(int objectiveNr)
          This method does a recursive depth-first search on the subtree that is rooted at the receiver, and returns the first Objective or Issue with the given number.
 Objective getParent()
           
 javax.swing.tree.TreePath getPath()
           
 java.util.Enumeration<Objective> getPreorderEnumeration()
          Constructs an Enumeration of the entire subtree of the receiver (including itself) in preorder.
 java.util.Enumeration<Objective> getPreorderIssueEnumeration()
          Constructs an Enumeration of the entire subtree of the receiver (including itself) in preorder, containing only the Issues, but not the normal Objectives.
 java.util.Enumeration<Objective> getPreorderObjectiveEnumeration()
          Constructs an Enumeration of the entire subtree of the receiver (including itself) in preorder, containting only the Ojectives, but not the Issues..
 Objective[] getSiblings()
           
 ISSUETYPE getType()
          This method is added for convenience.
 java.lang.Object getUserObject()
           
 int hashCode()
           
 void insert(javax.swing.tree.MutableTreeNode child, int index)
          Adds child to the receiver at index.
 boolean isIssue()
           
 boolean isLeaf()
           
 boolean isObjective()
           
 boolean isParent(Objective child)
          Check whether or not a particular Objective is a child of the receiver.
 void remove(int index)
          Removes the child at the given index, setting it's parent to null.
 void remove(javax.swing.tree.MutableTreeNode node)
          Removes node from the receiver's children, and sets it's parent to null.
 void removeFromParent()
          Removes the subtree rooted at this node from the tree, giving this node a null parent.
 void setDescription(java.lang.String newDescription)
          Sets a new description for this node.
 void setName(java.lang.String newName)
          Sets a new name for this node.
 void setNumber(int nr)
          Sets the number of this Objective / Issue.
 void setParent(javax.swing.tree.MutableTreeNode newParent)
          Sets this node's parent to newParent but does not change the parent's child array.
 void setUserObject(java.lang.Object object)
          Sets a user object associated with the receiving Objective.
 java.lang.String toString()
           
 SimpleElement toXML()
          Returns an xml representation of this Objective and all Objectives and issues underneath it.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Objective

public Objective()

Objective

public Objective(Objective parent)

Objective

public Objective(Objective parent,
                 java.lang.String name)

Objective

public Objective(Objective parent,
                 java.lang.String name,
                 int nr)
Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object
Returns:
true if given object is an Objective and number, name, and children are the same we don't care about the description and user objects.

equalContents

public boolean equalContents(Objective obj)
check the contents but don't check for the class type anymore.

Parameters:
obj - the objective to be compared
Returns:
true if number, name, and children are the same we don't care about the description and user objects.

getName

public java.lang.String getName()
Returns:
the name of this node.

setName

public void setName(java.lang.String newName)
Sets a new name for this node.

Parameters:
newName - the new name for this node.

getNumber

public int getNumber()
Returns:
the number of this Objective / Issue.

setNumber

public void setNumber(int nr)
Sets the number of this Objective / Issue.


getDescription

public java.lang.String getDescription()
Returns:
this node's description.

setDescription

public void setDescription(java.lang.String newDescription)
Sets a new description for this node.

Parameters:
newDescription - the new description.

getUserObject

public java.lang.Object getUserObject()
Returns:
the user object containted within this node.

isObjective

public boolean isObjective()
Returns:
true if and only if this node is of the Objective type, but not of the Issue type. This is implemented by looking if the receiver is instanceof Objective, but not instanceof Issue.

isIssue

public boolean isIssue()
Returns:
true if and only if this node is of the Issue type. It is implemented with instanceof Issue.

getType

public ISSUETYPE getType()
This method is added for convenience. It is simply an alternative implementation of the getType method from the Issue class. It will always return that the type is Objective. This method must be overridden in Issue to return the type of the Issue.

Returns:
ISSUETYPE.OBJECTIVE

addChild

public void addChild(Objective newObjective)
Adds a child to this Objective. The new child must be an Objective or an issue. The child is messaged to set it's parent to the receiver.

Parameters:
newObjective - a child to be added to this Objective.

getObjective

public Objective getObjective(int objectiveNr)
This method does a recursive depth-first search on the subtree that is rooted at the receiver, and returns the first Objective or Issue with the given number. If there is no matching node found, null is returned.

Parameters:
objectiveNr - the Objective/Issue number that is being searched for.
Returns:
the Objective/Issue with the given number, or null if the requested Objective/Issue is nog found in the subtree that is rooted at the receiver. Wouter: this seems overly difficult????

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
the name of this Objective.

getSiblings

public Objective[] getSiblings()
Returns:
an Objective[] containing this node's siblings, or an empty array if this Objective's parent is null.

isParent

public boolean isParent(Objective child)
Check whether or not a particular Objective is a child of the receiver. Comparison is based on simple pointer comparison.

Parameters:
child - the potential child of the callee.
Returns:
true iff child is a direct child of the receiving node.

children

public java.util.Enumeration<Objective> children()
Specified by:
children in interface javax.swing.tree.TreeNode
Returns:
an Enumeration of this Objective's children.

getChildren

public java.util.ArrayList<Objective> getChildren()
Wouter: added bcause I dont have time to change all Vector and Enumerators to ArrayList code


getAllowsChildren

public boolean getAllowsChildren()
Specified by:
getAllowsChildren in interface javax.swing.tree.TreeNode
Returns:
true iff the node is an OBJECTIVE, of false if the node is an ISSUE.

getChildAt

public Objective getChildAt(int childIndex)
Specified by:
getChildAt in interface javax.swing.tree.TreeNode
Returns:
the child at the given index, or null if the index is invalid.

getChildWithID

public Objective getChildWithID(int ID)
Parameters:
ID - is the ID number of the needed child
Returns:
Objective, or null.

getChildCount

public int getChildCount()
Specified by:
getChildCount in interface javax.swing.tree.TreeNode
Returns:
the number of children of this node.

getIndex

public int getIndex(javax.swing.tree.TreeNode node)
Specified by:
getIndex in interface javax.swing.tree.TreeNode
Returns:
the index of node in the receivers children. If the receiver does not contain node, -1 will be returned.

getParent

public Objective getParent()
Specified by:
getParent in interface javax.swing.tree.TreeNode
Returns:
the parent Objective of the receiver.

isLeaf

public boolean isLeaf()
Specified by:
isLeaf in interface javax.swing.tree.TreeNode
Returns:
is the receiving node is a leaf node. A Objective is a leaf node when it is of the ISSUE type.

getHighestObjectiveNr

public int getHighestObjectiveNr(int lowerBound)
This method recursively calculates the highest Objective / Issue number in the subtree rooted at the callee.

Parameters:
lowerBound - the number to be returned must have at least this value. Used for the recursive implementation.
Returns:
the highest Objective number within this subtree that is greater than lowerBound, or otherwise lowerBound.

insert

public void insert(javax.swing.tree.MutableTreeNode child,
                   int index)
Adds child to the receiver at index. child will be messaged with setParent. Nodes at the given index and above are moved one place up to make room for the new node. If index > getChildCount() or index < 0, nothing happens.

Specified by:
insert in interface javax.swing.tree.MutableTreeNode
Parameters:
child - the Objective to be inserted. If child is no NegotionTreeNode, a ClassCastException will be thrown.
index - the index where the new node is to be inserted.

remove

public void remove(int index)
Removes the child at the given index, setting it's parent to null. If index >= getChildCount or index < 0, nothing happens.

Specified by:
remove in interface javax.swing.tree.MutableTreeNode

remove

public void remove(javax.swing.tree.MutableTreeNode node)
Removes node from the receiver's children, and sets it's parent to null. If node is not one of the receiver's children, nothing happens.

Specified by:
remove in interface javax.swing.tree.MutableTreeNode

removeFromParent

public void removeFromParent()
Removes the subtree rooted at this node from the tree, giving this node a null parent. Does nothing if this node is the root of its tree.

Specified by:
removeFromParent in interface javax.swing.tree.MutableTreeNode

setParent

public void setParent(javax.swing.tree.MutableTreeNode newParent)
Sets this node's parent to newParent but does not change the parent's child array. This method is called from insert() and remove() to reassign a child's parent, it should not be messaged from anywhere else. Also, newParent is cast to a Objective. Calling this method with a different type of TreeNode will result in a ClassCastException.

Specified by:
setParent in interface javax.swing.tree.MutableTreeNode

setUserObject

public void setUserObject(java.lang.Object object)
Sets a user object associated with the receiving Objective. This method is primarily available in order to implement the MutableTreeNode interface, but because the user object can be of any type it may well be used to associate extra information about the node. For instance a picture of this node's OBJECTIVE or ISSUE.

Specified by:
setUserObject in interface javax.swing.tree.MutableTreeNode

getPreorderEnumeration

public java.util.Enumeration<Objective> getPreorderEnumeration()
Constructs an Enumeration of the entire subtree of the receiver (including itself) in preorder. The enumeration is immediately constructed against the current state of the tree, so modifications to the tree afterwards are not reflected in the Enumeration.

Returns:
the preorder Enumeration of the subtree.

getPreorderObjectiveEnumeration

public java.util.Enumeration<Objective> getPreorderObjectiveEnumeration()
Constructs an Enumeration of the entire subtree of the receiver (including itself) in preorder, containting only the Ojectives, but not the Issues.. The enumeration is immediately constructed against the current state of the tree, so modifications to the tree afterwards are not reflected in the Enumeration.

Returns:
the preorder Enumeration of Objectives from the subtree.

getPreorderIssueEnumeration

public java.util.Enumeration<Objective> getPreorderIssueEnumeration()
Constructs an Enumeration of the entire subtree of the receiver (including itself) in preorder, containing only the Issues, but not the normal Objectives. The enumeration is immediately constructed against the current state of the tree, so modifications to the tree afterwards are not reflected in the Enumeration.

Returns:
the preorder Enumeration of Issues from the subtree.

toXML

public SimpleElement toXML()
Returns an xml representation of this Objective and all Objectives and issues underneath it.


getPath

public javax.swing.tree.TreePath getPath()
Returns:
treepath to (and including) this objective. requires that the parent fields are set properly and that this implements MutableTreeNode. Still, it is dubious whether Objective should implement mutabletreenode...